/*
 * GwtRpcNetTestEntryPoint.java
 *
 * Created on 19 december 2007, 22:37
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.gwtrpcnettest.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 *
 * @author Mark
 */
public class GwtRpcNetTestEntryPoint implements EntryPoint {
    
    final Label label = new Label("Hello, GWT!!!");
    
    /** Creates a new instance of GwtRpcNetTestEntryPoint */
    public GwtRpcNetTestEntryPoint() {
    }
    
    /**
     * The entry point method, called automatically by loading a module
     * that declares an implementing class as an entry-point
     */
    public void onModuleLoad() {
        final Button button = new Button("Click me!");
        
        button.addClickListener(new ClickListener(){
            public void onClick(Widget w) {
                handleClickOne();
            }
        });
        
        RootPanel.get().add(button);
        RootPanel.get().add(label);
    }
    
    private void handleClickOne() {
        AsyncCallback callback = new AsyncCallback() {
            public void onSuccess(Object result) {
                    label.setText(((Person)result).getName());
                    //label.setText(result.toString());
            }

            public void onFailure(Throwable caught) {
                    label.setText(caught.toString());
            }
        };    
        Person p = new Person("mark", "jefke2212@gmail.com", 25);
        //GWTNetTestServiceUsageExample.getService().myMethod("mark", callback);
        GWTNetTestServiceUsageExample.getService().doPerson(p, callback);
    }
    
}
